package penguin.masking.filter;

import penguin.masking.MaskingContext;
import penguin.masking.jdbc.DBMetaHandler;
import penguin.masking.jdbc.MetaHandlerFactory;

import java.sql.ResultSet;
import java.util.List;

/**
 * 用户过滤
 *
 * @author wuxh
 * @version 1.0.0
 */
public class UserFilter implements MaskingFilter {

    @Override
    public boolean doFilter(ResultSet set, Object columnName, int columnIndex) {
        List<String> users = MaskingContext.context().getUsers();
        if (!users.isEmpty() && columnIndex > 0) {
            DBMetaHandler handler = MetaHandlerFactory.getInstance().handler(set);
            String userName = handler.userName(set);
            if (!users.contains(userName)) {
                return true;
            }
        }
        return false;
    }
}
